home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / SLMaping.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  25.6 KB  |  893 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLMaping.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWMAPING_H
  13. #include "SLMaping.h"
  14. #endif
  15.  
  16. #ifndef PRGDEV_H
  17. #include "PRGDev.h"
  18. #endif
  19.  
  20. #ifndef SLREGION_H
  21. #include "SLRegion.h"
  22. #endif
  23.  
  24. #ifndef FWACQUIR_H
  25. #include "FWAcquir.h"
  26. #endif
  27.  
  28. #ifndef FWGRUTIL_H
  29. #include "FWGrUtil.h"
  30. #endif
  31.  
  32. #ifndef FWODGEOM_H
  33. #include "FWODGeom.h"
  34. #endif
  35.  
  36. #ifndef FWSOMENV_H
  37. #include "FWSOMEnv.h"
  38. #endif
  39.  
  40. // ----- OpenDoc Includes -----
  41.  
  42. #ifndef SOM_ODTransform_xh
  43. #include <Trnsform.xh>
  44. #endif
  45.  
  46. #ifndef SOM_ODShape_xh
  47. #include <Shape.xh>
  48. #endif
  49.  
  50. #ifdef FW_BUILD_MAC
  51. #pragma segment FW_Graphics
  52. #endif
  53.  
  54. //========================================================================================
  55. //    Local prototypes
  56. //========================================================================================
  57.  
  58. static void                ClearCache(FW_SMapping& mapping, Environment* ev);
  59.  
  60. static void                CheckCache(
  61.                             const FW_SMapping& mapping,
  62.                             Environment* ev,
  63.                             FW_HGDevice device,
  64.                             ODTransform* transform);
  65.  
  66. static void                CalcCache(
  67.                             FW_SMapping& mapping,
  68.                             Environment* ev,
  69.                             FW_HGDevice device,
  70.                             ODTransform* transform);
  71.  
  72. static void                CalcOriginOffset(
  73.                             FW_SMapping& mapping,
  74.                             Environment* ev,
  75.                             FW_HGDevice device);
  76.  
  77. //========================================================================================
  78. //    Mapping functions
  79. //========================================================================================
  80.  
  81. //----------------------------------------------------------------------------------------
  82. //    FW_PrivMapping_Init
  83. //----------------------------------------------------------------------------------------
  84.  
  85. void SL_API FW_PrivMapping_Init(FW_SMapping& mapping, FW_EMappingModes mappingMode)
  86. {
  87.     // No try block necessary - Do not throw
  88.     mapping.fMappingMode                =     mappingMode;
  89.     mapping.fRecentDevice                =    NULL;
  90.     mapping.fRecentODTransform            =    NULL;
  91.     mapping.fLogicalToContentTransform    =    NULL;
  92.     mapping.fContentToDeviceTransform    =    NULL;
  93.     mapping.fLogicalToDeviceTransform    =    NULL;
  94.     mapping.fHaveTransforms                =    FALSE;
  95.  
  96.     mapping.fDeviceOrg.x                 = 
  97.     mapping.fDeviceOrg.y                 = 
  98.     mapping.fLogicalOrg.x                 = 
  99.     mapping.fLogicalOrg.y                 =    FW_kFixed0;
  100.  
  101.     mapping.fLogicalExtent.x             =
  102.     mapping.fLogicalExtent.y             =
  103.     mapping.fDeviceExtent.x             =
  104.     mapping.fDeviceExtent.y             =    FW_kFixedPos1;
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_PrivMapping_InitFromCopy
  109. //----------------------------------------------------------------------------------------
  110.  
  111. void SL_API FW_PrivMapping_InitFromCopy(FW_SMapping& mapping, const FW_SMapping& mapping2)
  112. {
  113.     // No try block necessary - Do not throw
  114.     mapping.fMappingMode                =     mapping2.fMappingMode;
  115.     mapping.fRecentDevice                =    NULL;
  116.     mapping.fRecentODTransform            =    NULL;
  117.     mapping.fLogicalToContentTransform    =    NULL;
  118.     mapping.fContentToDeviceTransform    =    NULL;
  119.     mapping.fLogicalToDeviceTransform    =    NULL;
  120.     mapping.fHaveTransforms                =    FALSE;
  121.  
  122.     mapping.fDeviceOrg                     =    mapping2.fDeviceOrg;
  123.     mapping.fLogicalOrg                 =     mapping2.fLogicalOrg;
  124.  
  125.     mapping.fLogicalExtent                 =    mapping2.fLogicalExtent;
  126.     mapping.fDeviceExtent                 =    mapping2.fDeviceExtent;
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    FW_PrivMapping_Term
  131. //----------------------------------------------------------------------------------------
  132.  
  133. void SL_API FW_PrivMapping_Term(FW_SMapping& mapping, Environment* ev)
  134. {
  135.     // No try block necessary - Do not throw
  136.     ClearCache(mapping, ev);
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    FW_PrivMapping_Reset
  141. //----------------------------------------------------------------------------------------
  142.  
  143. void SL_API FW_PrivMapping_Reset(FW_SMapping& mapping, Environment* ev)
  144. {
  145.     // No try block necessary - Do not throw
  146.     ClearCache(mapping, ev);
  147.     
  148.     mapping.fMappingMode = FW_kPoint;
  149.  
  150.     mapping.fLogicalExtent.x =
  151.     mapping.fLogicalExtent.y =
  152.     mapping.fDeviceExtent.x =
  153.     mapping.fDeviceExtent.y = FW_kFixedPos1;
  154.  
  155.     mapping.fDeviceOrg = FW_kZeroPoint;
  156.     mapping.fLogicalOrg = FW_kZeroPoint;
  157. }
  158.  
  159. //----------------------------------------------------------------------------------------
  160. //    FW_PrivMapping_SetMode
  161. //----------------------------------------------------------------------------------------
  162.  
  163. void SL_API FW_PrivMapping_SetMode(FW_SMapping& mapping, Environment* ev, FW_EMappingModes newMappingMode)
  164. {
  165.     // No try block necessary - Do not throw
  166.     mapping.fMappingMode = newMappingMode;
  167.     
  168.     if (mapping.fMappingMode == FW_kCustomConstrained)
  169.         FW_PrivMapping_SetExtents(mapping, ev, mapping.fLogicalExtent, mapping.fDeviceExtent);    // already calls ClearCache
  170.     else
  171.         ClearCache(mapping, ev);
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_PrivMapping_SetExtents
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void SL_API FW_PrivMapping_SetExtents(
  179.                                 FW_SMapping& mapping,
  180.                                 Environment* ev,
  181.                                 const FW_SPoint& logicalExtent,
  182.                                 const FW_SPoint& deviceExtent)
  183. {
  184.     // No try block necessary - Do not throw
  185.     mapping.fLogicalExtent = logicalExtent;
  186.     mapping.fDeviceExtent = deviceExtent;
  187.     ClearCache(mapping, ev);
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_PrivMapping_SetDeviceOrigin
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void SL_API FW_PrivMapping_SetDeviceOrigin(FW_SMapping& mapping, Environment* ev, FW_Fixed x, FW_Fixed y)
  195. {
  196.     // No try block necessary - Do not throw
  197.     mapping.fDeviceOrg.x = x;
  198.     mapping.fDeviceOrg.y = y;
  199.     ClearCache(mapping, ev);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_PrivMapping_SetLogicalOrigin
  204. //----------------------------------------------------------------------------------------
  205.  
  206. void SL_API FW_PrivMapping_SetLogicalOrigin(FW_SMapping& mapping, Environment* ev, FW_Fixed x, FW_Fixed y)
  207. {
  208.     // No try block necessary - Do not throw
  209.     mapping.fLogicalOrg.x = x;
  210.     mapping.fLogicalOrg.y = y;
  211.     ClearCache(mapping, ev);
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_PrivMapping_GetOriginOffset
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void SL_API FW_PrivMapping_GetOriginOffset(
  219.                                 const FW_SMapping& mapping,
  220.                                 Environment* ev,
  221.                                 FW_PlatformPoint& offset,
  222.                                 FW_HGDevice device,
  223.                                 ODTransform* transform)
  224. {
  225.     // No try block necessary - Do not throw
  226.     CheckCache(mapping, ev, device, transform);
  227.     offset = mapping.fOriginOffset;
  228. }
  229.  
  230. //========================================================================================
  231. //    Local helpers
  232. //========================================================================================
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    ClearCache
  236. //----------------------------------------------------------------------------------------
  237.  
  238. static void ClearCache(FW_SMapping& mapping, Environment* ev)
  239. {
  240.     // Will not throw
  241.     FW_SOM_TRY
  242.     {
  243.         if (mapping.fRecentDevice != NULL)
  244.         {
  245.             mapping.fRecentDevice->Release();
  246.             mapping.fRecentDevice = NULL;
  247.         }
  248.     
  249.         if (mapping.fRecentODTransform != NULL)
  250.         {
  251.             mapping.fRecentODTransform->Release(ev);
  252.             mapping.fRecentODTransform = NULL;
  253.         }
  254.     
  255.         if (mapping.fLogicalToContentTransform != NULL)
  256.         {
  257.             mapping.fLogicalToContentTransform->Release(ev);
  258.             mapping.fLogicalToContentTransform = NULL;
  259.         }
  260.     
  261.         if (mapping.fContentToDeviceTransform != NULL)
  262.         {
  263.             mapping.fContentToDeviceTransform->Release(ev);
  264.             mapping.fContentToDeviceTransform = NULL;
  265.         }
  266.     
  267.         if (mapping.fLogicalToDeviceTransform != NULL)
  268.         {
  269.             mapping.fLogicalToDeviceTransform->Release(ev);
  270.             mapping.fLogicalToDeviceTransform = NULL;
  271.         }
  272.         
  273.         mapping.fHaveTransforms = FALSE;
  274.     }
  275.     FW_SOM_CATCH
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //    CheckCache
  280. //----------------------------------------------------------------------------------------
  281.  
  282. static void CheckCache(const FW_SMapping& mapping,
  283.                         Environment* ev,
  284.                         FW_HGDevice device,
  285.                         ODTransform* transform)
  286. {
  287.     // No try block necessary - Do not throw
  288.     if (!mapping.fHaveTransforms || device != mapping.fRecentDevice || transform != mapping.fRecentODTransform)
  289.         CalcCache((FW_SMapping&)mapping, ev, device, transform);
  290.  
  291.     FW_ASSERT(mapping.fHaveTransforms);
  292.     FW_ASSERT(mapping.fLogicalToContentTransform != NULL);
  293.     FW_ASSERT(mapping.fContentToDeviceTransform != NULL);
  294.     FW_ASSERT(mapping.fLogicalToDeviceTransform != NULL);
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. //    CalcCache
  299. //----------------------------------------------------------------------------------------
  300.  
  301. static void CalcCache(FW_SMapping& mapping,
  302.                     Environment* ev,
  303.                     FW_HGDevice device,
  304.                     ODTransform* transform)
  305. {
  306. // #define LOG_TRANSFORMS
  307.  
  308.     FW_SOM_TRY
  309.     {
  310.         ClearCache(mapping, ev);
  311.     
  312.         mapping.fRecentDevice = device;
  313.         if (mapping.fRecentDevice != NULL)
  314.             mapping.fRecentDevice->Acquire();
  315.             
  316.         mapping.fRecentODTransform = transform;
  317.         if (mapping.fRecentODTransform != NULL) 
  318.             mapping.fRecentODTransform->Acquire(ev);
  319.     
  320.         ODCanvas* canvas = device != NULL ? device->GetODCanvas() : NULL;
  321.         
  322.     #ifdef FW_BUILD_WIN
  323.         FW_CPoint resScreen;
  324.  
  325.         HDC hDC = ::GetDC(NULL);
  326.     
  327.         resScreen.x    = FW_IntToFixed(::GetDeviceCaps(hDC, LOGPIXELSX));
  328.         resScreen.y    = FW_IntToFixed(::GetDeviceCaps(hDC, LOGPIXELSY));
  329.     
  330.         ::ReleaseDC(NULL, hDC);
  331.         
  332.         BOOL bWinIsPrinting = canvas != NULL ? canvas->HasPlatformPrintJob(ev, kODWin32) : FALSE;
  333.     #endif
  334.     #ifdef FW_BUILD_MAC
  335.         const FW_CPoint resScreen(FW_kFixed72, FW_kFixed72);
  336.     #endif
  337.     
  338.         FW_CPoint resDevice = device == NULL ? resScreen : device->GetResolution();
  339.             
  340.         FW_CPoint ptLogicalToContentOffset(-mapping.fLogicalOrg.x, -mapping.fLogicalOrg.y);
  341.  
  342.         // initialize scaling to 1/1
  343.         FW_CPoint ptLogicalToContentScaling(FW_kFixedPos1, FW_kFixedPos1);
  344.     
  345.         //    ptLogicalToContentScaling: the number of device pixels per logical unit.
  346.         //    for example:
  347.         //    FW_kCentimeter:    1 unit (1 centimeter) == 28.346 content units (content == 72dpi)
  348.         //    FW_kPoint:        1 unit (1 point == 1/72 in.) == 1 content units (content == 72dpi)
  349.         //    FW_kDevice:        1 unit (1 pixel) == 72 dpi / deviceDPI // content == 72dpi)
  350.                 
  351.         switch (mapping.fMappingMode)
  352.         {
  353.             case FW_kCentimeter:
  354.                 ptLogicalToContentScaling.x =
  355.                 ptLogicalToContentScaling.y = FW_DoubleToFixed(28.346456691);
  356.                 break;
  357.     
  358.             case FW_kInch:
  359.                 ptLogicalToContentScaling.x =
  360.                 ptLogicalToContentScaling.y = FW_kFixed72;
  361.                 break;
  362.     
  363.             case FW_kPoint:    
  364.                 //    On the Mac:
  365.                 //        The screen is always assumed to be 72dpi, even though actual
  366.                 //        resolution may vary (this is the tradition!)
  367.                 //    On Windows:
  368.                 //        OpenDoc/Win emulates 72dpi
  369.                 FW_ASSERT(ptLogicalToContentScaling.x == FW_kFixedPos1);
  370.                 FW_ASSERT(ptLogicalToContentScaling.y == FW_kFixedPos1);
  371.                 break;
  372.     
  373.             case FW_kDevice:
  374.     #ifdef FW_BUILD_MAC
  375.                 ptLogicalToContentScaling.x = FW_kFixed72 / resDevice.x;
  376.                 ptLogicalToContentScaling.y = FW_kFixed72 / resDevice.y;
  377.     #endif
  378.     #ifdef FW_BUILD_WIN
  379.                 if (bWinIsPrinting)
  380.                 {
  381.                     // For printing, preserve the visual image size
  382.                     ptLogicalToContentScaling.x = FW_kFixed72 / resScreen.x;
  383.                     ptLogicalToContentScaling.y = FW_kFixed72 / resScreen.y;
  384.                 }
  385.                 else
  386.                 {
  387.                     // Counter-act OpenDoc's 72 dpi emulation
  388.                     ptLogicalToContentScaling.x = FW_kFixed72 / resDevice.x;
  389.                     ptLogicalToContentScaling.y = FW_kFixed72 / resDevice.y;
  390.                 }
  391.     #endif
  392.                 break;
  393.     
  394.             case FW_kCustomConstrained:
  395.                 {
  396.                     FW_Fixed oneUnitx = mapping.fDeviceExtent.x / mapping.fLogicalExtent.x / resDevice.x;
  397.                     FW_Fixed oneUnity = mapping.fDeviceExtent.y / mapping.fLogicalExtent.y / resDevice.y;
  398.                     if (oneUnitx < oneUnity)
  399.                         mapping.fDeviceExtent.y = oneUnitx * resDevice.y * mapping.fLogicalExtent.y;
  400.                     else if (oneUnitx > oneUnity)
  401.                         mapping.fDeviceExtent.x = oneUnity * resDevice.x * mapping.fLogicalExtent.x;
  402.                 }
  403.                 // continue                
  404.             case FW_kCustomUnconstrained:
  405. #if 1
  406.                 FW_CPoint resScale;
  407.             
  408.                 // start with FW_kDevice 
  409.                 resScale.x = FW_kFixed72 / resDevice.x;
  410.                 resScale.y = FW_kFixed72 / resDevice.y;
  411.     
  412.                 ptLogicalToContentScaling.x =
  413.                     FW_WideMultiply(resScale.x, mapping.fDeviceExtent.x) / mapping.fLogicalExtent.x;
  414.                     
  415.                 ptLogicalToContentScaling.y =
  416.                     FW_WideMultiply(resScale.y, mapping.fDeviceExtent.y) / mapping.fLogicalExtent.y;
  417.     
  418.                 ptLogicalToContentOffset.x  = 
  419.                     FW_WideMultiply(mapping.fDeviceOrg.x, FW_kFixed72) / resDevice.x - mapping.fLogicalOrg.x * ptLogicalToContentScaling.x;
  420.     
  421.                 ptLogicalToContentOffset.y  =
  422.                     FW_WideMultiply(mapping.fDeviceOrg.y, FW_kFixed72) / resDevice.y - mapping.fLogicalOrg.y * ptLogicalToContentScaling.y;
  423. #else
  424.                 ptLogicalToContentScaling.x = mapping.fDeviceExtent.x / mapping.fLogicalExtent.x;
  425.                     
  426.                 ptLogicalToContentScaling.y = mapping.fDeviceExtent.y / mapping.fLogicalExtent.y;
  427.     
  428.                 ptLogicalToContentOffset.x  = 
  429.                     FW_WideMultiply(mapping.fDeviceOrg.x, FW_kFixed72) / resDevice.x - mapping.fLogicalOrg.x * ptLogicalToContentScaling.x;
  430.     
  431.                 ptLogicalToContentOffset.y  =
  432.                     FW_WideMultiply(mapping.fDeviceOrg.y, FW_kFixed72) / resDevice.y - mapping.fLogicalOrg.y * ptLogicalToContentScaling.y;
  433. #endif
  434.                 break;
  435.         }
  436.  
  437.         // although we take the device resolution into account in various
  438.         // places here, since all OpenDoc parts don't use ODF, and Non-ODF parts
  439.         // may be in an ODF container, the print scaling is accomplished by using the bias
  440.         // transform of the printer canvas. See FW_CPrintJob The world would be
  441.         // much simpler if we could just deal with the printer resolution here.
  442.         
  443.         // ----- Logical to content transform
  444.         mapping.fLogicalToContentTransform = ::FW_NewODTransform(ev, ptLogicalToContentOffset, ptLogicalToContentScaling);
  445.     
  446.         // ----- Content to device transform
  447.         if(transform != NULL)
  448.         {
  449.     #ifdef LOG_TRANSFORMS
  450.             FW_LogTransform(ev, "OD Content        ", transform);
  451.     #endif
  452.             mapping.fContentToDeviceTransform = ::FW_NewODTransform(ev, transform);
  453.             
  454.             if(canvas != NULL)
  455.             {
  456.                 FW_CAcquiredODTransform bias = canvas->AcquireBiasTransform(ev);
  457.                 if(bias != NULL)
  458.                     mapping.fContentToDeviceTransform->PostCompose(ev, bias);
  459.             }
  460.         }
  461.         else
  462.         {
  463.             FW_CPoint scaling;
  464.     #ifdef FW_BUILD_WIN
  465.             if (bWinIsPrinting && mapping.fMappingMode == FW_kDevice)
  466.             {
  467.                 // Preserve visual image size
  468.                 scaling.x = resScreen.x / FW_kFixed72;
  469.                 scaling.y = resScreen.y / FW_kFixed72;
  470.             }
  471.             else
  472.     #endif
  473.             {
  474.                 scaling.x = resDevice.x / FW_kFixed72;
  475.                 scaling.y = resDevice.y / FW_kFixed72;
  476.             }
  477.     
  478.             mapping.fContentToDeviceTransform = ::FW_NewODTransform(ev);
  479.             mapping.fContentToDeviceTransform->ScaleBy(ev, (ODPoint*) &scaling);        
  480.         }
  481.     
  482.         // ------ Logical to device transform -----
  483.         mapping.fLogicalToDeviceTransform = ::FW_NewODTransform(ev, mapping.fLogicalToContentTransform);
  484.         mapping.fLogicalToDeviceTransform->PostCompose(ev, mapping.fContentToDeviceTransform);
  485.     
  486.         // ----- Adjust the origin
  487.         CalcOriginOffset(mapping, ev, device);
  488.     
  489.     #ifdef LOG_TRANSFORMS
  490.         FW_LogTransform(ev, "Logical -> Content", mapping.fLogicalToContentTransform);
  491.         FW_LogTransform(ev, "Content -> Device ", mapping.fContentToDeviceTransform);
  492.         FW_LogTransform(ev, "Logical -> Device ", mapping.fLogicalToDeviceTransform);
  493.     #endif
  494.     
  495.         mapping.fHaveTransforms = TRUE;
  496.     }
  497.     FW_SOM_CATCH
  498. }
  499.  
  500. //----------------------------------------------------------------------------------------
  501. //    CalcOriginOffset
  502. //----------------------------------------------------------------------------------------
  503.  
  504. static void CalcOriginOffset(FW_SMapping& mapping,
  505.                             Environment* ev,
  506.                             FW_HGDevice device)
  507. {
  508.     FW_SOM_TRY
  509.     {
  510.         ODCanvas* canvas = device != NULL ? device->GetODCanvas() : NULL;
  511.         FW_Boolean isPrinting = canvas != NULL && 
  512.     #ifdef FW_BUILD_WIN
  513.             (canvas->HasPlatformPrintJob(ev, kODWin32));
  514.     #endif
  515.     #ifdef FW_BUILD_MAC
  516.             (canvas->HasPlatformPrintJob(ev, kODQuickDrawGX) || canvas->HasPlatformPrintJob(ev, kODQuickDraw));
  517.     #endif
  518.     
  519.         FW_CPoint offset;
  520.         mapping.fLogicalToDeviceTransform->GetOffset(ev, offset);
  521.         if ((offset.x == FW_kFixed0 && offset.y == FW_kFixed0) || isPrinting)
  522.         {
  523.             FW_SetXY(mapping.fOriginOffset, 0, 0);
  524.         }
  525.         else
  526.         {
  527.             const short offsetX = FW_FixedToInt(offset.x);
  528.             const short offsetY = FW_FixedToInt(offset.y);
  529.             
  530. //            if(isPrinting)
  531. //            {
  532. //                // for some reason, we perform no pat align fudging on printers
  533. //                FW_SetXY(mapping.fOriginOffset, offsetX, offsetY);
  534. //            }
  535. //            else
  536.             {
  537.                 // this ensures that pattern drawing is aligned for 8x8 patterns
  538.                 FW_SetXY(mapping.fOriginOffset, offsetX % 8, offsetY % 8);
  539.                 offset.x = FW_IntToFixed(-FW_PointX(mapping.fOriginOffset));
  540.                 offset.y = FW_IntToFixed(-FW_PointY(mapping.fOriginOffset));
  541.                 mapping.fLogicalToDeviceTransform->MoveBy(ev, offset);
  542.             }
  543.         }
  544.     }
  545.     FW_SOM_CATCH
  546. }
  547.  
  548. //----------------------------------------------------------------------------------------
  549. // ----- Logical ---> Content
  550. //----------------------------------------------------------------------------------------
  551.  
  552. void SL_API FW_PrivMapping_LogicalToContentPoint(
  553.                                 const FW_SMapping& mapping,
  554.                                 Environment* ev,
  555.                                 const FW_SPoint& ptFrom,
  556.                                 FW_SPoint& ptTo,
  557.                                 FW_HGDevice device,
  558.                                 ODTransform* transform)
  559. {
  560.     FW_SOM_TRY
  561.     {
  562.         CheckCache(mapping, ev, device, transform);
  563.         ptTo = FW_TransformCopy(ev, ptFrom, mapping.fLogicalToContentTransform);
  564.     }
  565.     FW_SOM_CATCH
  566. }
  567.  
  568. void SL_API FW_PrivMapping_LogicalToContentRect(
  569.                                 const FW_SMapping& mapping,
  570.                                 Environment* ev,
  571.                                 const FW_SRect& rectFrom,
  572.                                 FW_SRect& rectTo,
  573.                                 FW_HGDevice device,
  574.                                 ODTransform* transform)
  575. {
  576.     FW_SOM_TRY
  577.     {
  578.         CheckCache(mapping, ev, device, transform);
  579.         rectTo = FW_TransformCopy(ev, rectFrom, mapping.fLogicalToContentTransform);
  580.     }
  581.     FW_SOM_CATCH
  582. }
  583.  
  584. ODShape* SL_API FW_PrivMapping_LogicalToContentShape(
  585.                                 const FW_SMapping& mapping,
  586.                                 Environment* ev,
  587.                                 ODShape* shape,
  588.                                 FW_HGDevice device,
  589.                                 ODTransform* transform)
  590. {
  591.     ODShape* newShape = 0;
  592.  
  593.     FW_SOM_TRY
  594.     {
  595.         CheckCache(mapping, ev, device, transform);
  596.         newShape = shape->Copy(ev);
  597.         mapping.fLogicalToContentTransform->TransformShape(ev, newShape);
  598.     }
  599.     FW_SOM_CATCH
  600.  
  601.     return newShape;
  602. }
  603.  
  604. //----------------------------------------------------------------------------------------
  605. // ----- Logical ---> Device
  606. //----------------------------------------------------------------------------------------
  607.  
  608. void SL_API FW_PrivMapping_LogicalToDevicePoint(
  609.                                 const FW_SMapping& mapping,
  610.                                 Environment* ev,
  611.                                 const FW_SPoint& ptFrom,
  612.                                 FW_PlatformPoint& ptTo,
  613.                                 FW_HGDevice device,
  614.                                 ODTransform* transform)
  615. {
  616.     FW_SOM_TRY
  617.     {
  618.         CheckCache(mapping, ev, device, transform);
  619.         FW_CPoint pt = FW_TransformCopy(ev, ptFrom, mapping.fLogicalToDeviceTransform);
  620.         ptTo = pt.AsPlatformPoint();
  621.     }
  622.     FW_SOM_CATCH
  623. }
  624.  
  625. void SL_API FW_PrivMapping_LogicalToDeviceRect(
  626.                                 const FW_SMapping& mapping,
  627.                                 Environment* ev,
  628.                                 const FW_SRect& rectFrom,
  629.                                 FW_PlatformRect& rectTo,
  630.                                 FW_HGDevice device,
  631.                                 ODTransform* transform)
  632. {
  633.     FW_SOM_TRY
  634.     {
  635.         CheckCache(mapping, ev, device, transform);
  636.         FW_CRect rect = FW_TransformCopy(ev, rectFrom, mapping.fLogicalToDeviceTransform);
  637.         rectTo = rect.AsPlatformRect();
  638.     }
  639.     FW_SOM_CATCH
  640. }
  641.  
  642. ODShape* SL_API FW_PrivMapping_LogicalToDeviceShape(
  643.                                 const FW_SMapping& mapping,
  644.                                 Environment* ev,
  645.                                 ODShape* shape,
  646.                                 FW_HGDevice device,
  647.                                 ODTransform* transform)
  648. {
  649.     ODShape* newShape = 0;
  650.  
  651.     FW_SOM_TRY
  652.     {
  653.         CheckCache(mapping, ev, device, transform);
  654.         newShape = shape->Copy(ev);
  655.         mapping.fLogicalToDeviceTransform->TransformShape(ev, newShape);
  656.     }
  657.     FW_SOM_CATCH
  658.  
  659.     return newShape;
  660. }
  661.  
  662. //----------------------------------------------------------------------------------------
  663. // ----- Device ---> Logical
  664. //----------------------------------------------------------------------------------------
  665.  
  666. void SL_API FW_PrivMapping_DeviceToLogicalPoint(
  667.                                 const FW_SMapping& mapping,
  668.                                 Environment* ev,
  669.                                 const FW_PlatformPoint& ptFrom,
  670.                                 FW_SPoint& ptTo,
  671.                                 FW_HGDevice device,
  672.                                 ODTransform* transform)
  673. {
  674.     FW_SOM_TRY
  675.     {
  676.         CheckCache(mapping, ev, device, transform);
  677.         FW_CPoint pt = ptFrom;
  678.         ptTo = FW_InverseTransformCopy(ev, pt, mapping.fLogicalToDeviceTransform);
  679.     }
  680.     FW_SOM_CATCH
  681. }
  682.  
  683. void SL_API FW_PrivMapping_DeviceToLogicalRect(
  684.                                 const FW_SMapping& mapping,
  685.                                 Environment* ev,
  686.                                 const FW_PlatformRect& rectFrom,
  687.                                 FW_SRect& rectTo,
  688.                                 FW_HGDevice device,
  689.                                 ODTransform* transform)
  690. {
  691.     FW_SOM_TRY
  692.     {
  693.         CheckCache(mapping, ev, device, transform);
  694.         FW_CRect rect = rectFrom;
  695.         rectTo = rect.InverseTransformCopy(ev, mapping.fLogicalToDeviceTransform);
  696.     }
  697.     FW_SOM_CATCH
  698. }
  699.     
  700. ODShape* SL_API FW_PrivMapping_DeviceToLogicalShape(
  701.                                 const FW_SMapping& mapping,
  702.                                 Environment* ev,
  703.                                 ODShape* shape,
  704.                                 FW_HGDevice device,
  705.                                 ODTransform* transform)
  706. {
  707.     ODShape* newShape = 0;
  708.  
  709.     FW_SOM_TRY
  710.     {
  711.         CheckCache(mapping, ev, device, transform);
  712.         newShape = shape->Copy(ev);
  713.         mapping.fLogicalToDeviceTransform->InvertShape(ev, newShape);
  714.     }
  715.     FW_SOM_CATCH
  716.  
  717.     return newShape;
  718. }
  719.  
  720. //----------------------------------------------------------------------------------------
  721. // ----- Device ---> Content
  722. //----------------------------------------------------------------------------------------
  723.  
  724. void SL_API FW_PrivMapping_DeviceToContentPoint(
  725.                                 const FW_SMapping& mapping,
  726.                                 Environment* ev,
  727.                                 const FW_PlatformPoint& ptFrom,
  728.                                 FW_SPoint& ptTo,
  729.                                 FW_HGDevice device,
  730.                                 ODTransform* transform)
  731. {
  732.     FW_SOM_TRY
  733.     {
  734.         CheckCache(mapping, ev, device, transform);
  735.         FW_CPoint pt = ptFrom;
  736.         ptTo = FW_InverseTransformCopy(ev, pt, mapping.fContentToDeviceTransform);
  737.     }
  738.     FW_SOM_CATCH
  739. }
  740.  
  741. void SL_API FW_PrivMapping_DeviceToContentRect(
  742.                                 const FW_SMapping& mapping,
  743.                                 Environment* ev,
  744.                                 const FW_PlatformRect& rectFrom,
  745.                                 FW_SRect& rectTo,
  746.                                 FW_HGDevice device,
  747.                                 ODTransform* transform)
  748. {
  749.     FW_SOM_TRY
  750.     {
  751.         CheckCache(mapping, ev, device, transform);
  752.         FW_CRect rect = rectFrom;
  753.         rectTo = rect.InverseTransformCopy(ev, mapping.fContentToDeviceTransform);
  754.     }
  755.     FW_SOM_CATCH
  756. }
  757.  
  758. ODShape* SL_API FW_PrivMapping_DeviceToContentShape(
  759.                                 const FW_SMapping& mapping,
  760.                                 Environment* ev,
  761.                                 ODShape* shape,
  762.                                 FW_HGDevice device,
  763.                                 ODTransform* transform)
  764. {
  765.     ODShape* newShape = 0;
  766.  
  767.     FW_SOM_TRY
  768.     {
  769.         CheckCache(mapping, ev, device, transform);
  770.         newShape = shape->Copy(ev);
  771.         mapping.fContentToDeviceTransform->InvertShape(ev, newShape);
  772.     }
  773.     FW_SOM_CATCH
  774.  
  775.     return newShape;
  776. }
  777.  
  778. //----------------------------------------------------------------------------------------
  779. // ----- Content ---> Logical
  780. //----------------------------------------------------------------------------------------
  781.                             
  782. void SL_API FW_PrivMapping_ContentToLogicalPoint(
  783.                                 const FW_SMapping& mapping,
  784.                                 Environment* ev,
  785.                                 const FW_SPoint& ptFrom,
  786.                                 FW_SPoint& ptTo,
  787.                                 FW_HGDevice device,
  788.                                 ODTransform* transform)
  789. {
  790.     FW_SOM_TRY
  791.     {
  792.         CheckCache(mapping, ev, device, transform);
  793.         ptTo = FW_InverseTransformCopy(ev, ptFrom, mapping.fLogicalToContentTransform);
  794.     }
  795.     FW_SOM_CATCH
  796. }
  797.     
  798. void SL_API FW_PrivMapping_ContentToLogicalRect(
  799.                                 const FW_SMapping& mapping,
  800.                                 Environment* ev,
  801.                                 const FW_SRect& rectFrom,
  802.                                 FW_SRect& rectTo,
  803.                                 FW_HGDevice device,
  804.                                 ODTransform* transform)
  805. {
  806.     FW_SOM_TRY
  807.     {
  808.         CheckCache(mapping, ev, device, transform);
  809.         rectTo = FW_InverseTransformCopy(ev, rectFrom, mapping.fLogicalToContentTransform);
  810.     }
  811.     FW_SOM_CATCH
  812. }
  813.                                 
  814.     
  815. ODShape* SL_API FW_PrivMapping_ContentToLogicalShape(
  816.                                 const FW_SMapping& mapping,
  817.                                 Environment* ev,
  818.                                 ODShape* shape,
  819.                                 FW_HGDevice device,
  820.                                 ODTransform* transform)
  821. {
  822.     ODShape* newShape = 0;
  823.  
  824.     FW_SOM_TRY
  825.     {
  826.         CheckCache(mapping, ev, device, transform);
  827.         newShape = shape->Copy(ev);
  828.         mapping.fLogicalToContentTransform->InvertShape(ev, newShape);
  829.     }
  830.     FW_SOM_CATCH
  831.  
  832.     return newShape;
  833. }
  834.  
  835. //----------------------------------------------------------------------------------------
  836. // ----- Content ---> Device
  837. //----------------------------------------------------------------------------------------
  838.  
  839. void SL_API FW_PrivMapping_ContentToDevicePoint(
  840.                                 const FW_SMapping& mapping,
  841.                                 Environment* ev,
  842.                                 const FW_SPoint& ptFrom,
  843.                                 FW_PlatformPoint& ptTo,
  844.                                 FW_HGDevice device,
  845.                                 ODTransform* transform)
  846. {
  847.     FW_SOM_TRY
  848.     {
  849.         CheckCache(mapping, ev, device, transform);
  850.         FW_CPoint pt = FW_TransformCopy(ev, ptFrom, mapping.fContentToDeviceTransform);
  851.         ptTo = pt.AsPlatformPoint();
  852.     }
  853.     FW_SOM_CATCH
  854. }
  855.  
  856. void SL_API FW_PrivMapping_ContentToDeviceRect(
  857.                                 const FW_SMapping& mapping,
  858.                                 Environment* ev,
  859.                                 const FW_SRect& rectFrom,
  860.                                 FW_PlatformRect& rectTo,
  861.                                 FW_HGDevice device,
  862.                                 ODTransform* transform)
  863. {
  864.     FW_SOM_TRY
  865.     {
  866.         CheckCache(mapping, ev, device, transform);
  867.         FW_CRect rect = FW_TransformCopy(ev, rectFrom, mapping.fContentToDeviceTransform);
  868.         rectTo = rect.AsPlatformRect();
  869.     }
  870.     FW_SOM_CATCH
  871. }
  872.  
  873. ODShape* SL_API FW_PrivMapping_ContentToDeviceShape(
  874.                                 const FW_SMapping& mapping,
  875.                                 Environment* ev,
  876.                                 ODShape* shape,
  877.                                 FW_HGDevice device,
  878.                                 ODTransform* transform)
  879. {
  880.     ODShape* newShape = 0;
  881.  
  882.     FW_SOM_TRY
  883.     {
  884.         CheckCache(mapping, ev, device, transform);
  885.         newShape = shape->Copy(ev);
  886.         mapping.fContentToDeviceTransform->TransformShape(ev, newShape);
  887.     }
  888.     FW_SOM_CATCH
  889.  
  890.     return newShape;
  891. }
  892.  
  893.